namespace ghost {
    export class BarObj extends NoDepthObj {        
        public roleBar:RoleBar;
        /**bar变更时间戳*/private _changeTime:number;
        /**bar隐藏间隔，默认NaN，不隐藏*/public hideInterval:number;
        private _valShieldHP: number = 0;
        private _valHp: number = 0;
        private _maxHp: number = 0;        
        public setSkin(skinObj: any): void {
            super.setSkin(skinObj);
            let s = this;              
            if(s.roleBar == null)            
                s.roleBar = new RoleBar();
            s.skin.addChild(s.roleBar);            
            s.roleBar.setBarSkin(s._cfg.barRes, s._cfg.barAtlas);
            s.roleBar.setBarWidth(s._cfg.barWidth,s._cfg.barOffsetX,s._cfg.barOffsetY);
            s.roleBar.setBarShadowSkin(s._cfg.barRes2, s._cfg.barAtlas);            
        }
        public setHp(val: number, max: number = NaN, shield:number=0, tween:boolean=true): void {
            let s = this;            
            s.roleBar.setBarValue(val, max==max?max:s._maxHp, shield, tween);
            if(s._valHp != val || s._valShieldHP > shield && shield > 0)
                s._changeTime = s._scene.timeTick;
            s._valShieldHP = shield;
            s._valHp = val;
            s._maxHp = max;
        }        
        public worldPosSet(): void {
            let s = this;
            let o:GameRole;
            o = <GameRole>s._owner;            
            s._skin.x = o.absX - s._scene.mapX;
            s._skin.y = o.absY - s._scene.mapY - o._headJumpH - s._floatH;
            if(s.roleBar)
            {
                s.roleBar.x = s._skinPart.getX();
                s.roleBar.y = s._skinPart.getY();
            }       
        }        
        
        public setVisible(val: boolean): void {
            let s = this; 
            val = val && s._valHp > 0 && (s.hideInterval != s.hideInterval || s._scene.timeTick - s._changeTime < s.hideInterval);
            if(s._visible == val)return;
			super.setVisible(val);
		}
        public beforeToPool(): void {
            super.beforeToPool();            
            let s = this;
            s.roleBar.clearTween();     
            s.roleBar.reset();            
        }
        public outPoolInit(): void {
            super.outPoolInit();            
            let s= this;
            s.hideInterval = NaN;            
        }
        public enterLoop(t: number, index: number): void 
		{
		}
    }
}